<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
	<th:block th:include="include :: header('修改租户')" />
	<th:block th:include="include :: datetimepicker-css" />
</head>
<body class="white-bg">
	<div class="wrapper wrapper-content animated fadeInRight ibox-content">
		<form class="form-horizontal m" id="form-tenant-edit" th:object="${tenant}">
			<input id="tenantId" name="tenantId" type="hidden" th:field="*{tenantId}"/>
			<div class="form-group">
				<label class="col-sm-3 control-label is-required">租户名称：</label>
				<div class="col-sm-8">
					<input class="form-control" placeholder="请输入租户名称" type="text" name="tenantName" id="tenantName" th:field="*{tenantName}" required>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label is-required">租户编码：</label>
				<div class="col-sm-8">
					<input class="form-control" placeholder="请输入租户编码" type="text" maxlength="30" name="tenantCode"  th:field="*{tenantCode}"  id="tenantCode" required>
				</div>
			</div>

			<div class="form-group">
				<label class="col-sm-3 control-label is-required">联系人：</label>
				<div class="col-sm-8">
					<input class="form-control" type="text" maxlength="30" name="contactName" th:field="*{contactName}" id="contactName" required>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label is-required">联系电话：</label>
				<div class="col-sm-8">
					<input class="form-control" type="text" maxlength="30" name="contactPhone" th:field="*{contactPhone}"  id="contactPhone" required>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label is-required">过期时间：</label>
				<div class="col-sm-8">
					<div class="radio-box" >
						<input type="radio"  th:field="*{expireStatus}" value="0" id="optionsRadios1" name="expireStatus" onclick="selectExpireStatus(0)" >
						<label for="optionsRadios1" onclick="selectExpireStatus(0)" >长期有效</label>
					</div>
					<div class="radio-box" >
						<input type="radio" value="1" th:field="*{expireStatus}" id="optionsRadios2" name="expireStatus" onclick="selectExpireStatus(1)" >
						<label for="optionsRadios2" onclick="selectExpireStatus(1)" >设置有效期</label>
					</div>
				</div>
			</div>
			<div class="form-group tempExpireDate" th:style="'display:' + @{(*{expireStatus} eq 0 ? 'none' : '')} + ''">
				<label class="col-sm-3 control-label">开始时间：</label>
				<div class="col-sm-8">
					<div class="input-group date"> <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
						<input type="text" name="expireBeginDate" class="form-control" th:field="*{expireBeginDate}" >
					</div>
				</div>
			</div>
			<div class="form-group tempExpireDate"  th:style="'display:' + @{(*{expireStatus} eq 0 ? 'none' : '')} + ''">
				<label class="col-sm-3 control-label">终止时间：</label>
				<div class="col-sm-8">
					<div class="input-group date"> <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
						<input type="text" name="expireEndDate" class="form-control" th:field="*{expireEndDate}" >
					</div>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label is-required">分校上限：</label>
				<div class="col-sm-8">
					<input class="form-control" th:field="*{campusNumLimit}" placeholder="请输入最多允许添加的分校数，0表示不受限制" type="text" maxlength="10" name="campusNumLimit" id="campusNumLimit" required>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label is-required">用户上限：</label>
				<div class="col-sm-8">
					<input class="form-control" th:field="*{userNumLimit}" placeholder="请输入最多允许添加的用户数，0表示不受限制" type="text" maxlength="10" name="userNumLimit" id="userNumLimit" required>
				</div>
			</div>

			<!--<div class="form-group">
				<label class="col-sm-3 control-label">租户状态：</label>
				<div class="col-sm-8">
					<div class="radio-box" th:each="dict : ${@dict.getType('sys_normal_disable')}">
						<input type="radio" th:id="${dict.dictCode}" name="status" th:value="${dict.dictValue}" th:field="*{status}">
						<label th:for="${dict.dictCode}" th:text="${dict.dictLabel}"></label>
					</div>
				</div>
			</div>-->
			<div class="form-group">
				<label class="col-sm-3 control-label">备注：</label>
				<div class="col-sm-8">
					<textarea id="remark" name="remark" class="form-control">[[*{remark}]]</textarea>
				</div>
			</div>
		</form>
	</div>
	<th:block th:include="include :: footer" />
	<th:block th:include="include :: datetimepicker-js" />
	<script type="text/javascript">
		var prefix = ctx + "system/tenant";
		
		$("#form-tenant-edit").validate({
			onkeyup: false,
			rules:{
				contactPhone: {
					required: true,
					isPhone:true
				},
				tenantName:{
					remote: {
		                url: prefix + "/checkTenantNameUnique",
		                type: "post",
		                dataType: "json",
		                data: {
		                	"tenantId": function() {
							    return $("input[name='tenantId']").val();
							},
		                	"tenantName" : function() {
		                        return $.common.trim($("#tenantName").val());
		                    }
		                },
		                dataFilter: function(data, type) {
		                	return $.validate.unique(data);
		                }
		            }
				},
				tenantCode:{
					remote: {
						url: ctx + "system/tenant/checkTenantCodeUnique",
						type: "post",
						dataType: "json",
						data: {
							"tenantId": function() {
								return $("input[name='tenantId']").val();
							},
							"tenantCode" : function() {
								return $.common.trim($("#tenantCode").val());
							}
						},
						dataFilter: function(data, type) {
							return $.validate.unique(data);
						}
					}
				},
				campusNumLimit:{
					digits:true
				},
				userNumLimit:{
					digits:true
				},
			},
			messages: {
		        "tenantName": {
		            remote: "租户名称已经存在！"
		        },
				"contactPhone": {
					remote: "请输入正确的联系人电话！"
				}
		    },
		    focusCleanup: true
		});
		
		function submitHandler() {
	        if ($.validate.form()) {
	        	$.operate.save(prefix + "/edit", $('#form-tenant-edit').serialize());
	        }
	    }


		$("input[name='expireBeginDate']").datetimepicker({
			autoclose: true,
			startDate: new Date()
		});

		$("input[name='expireEndDate']").datetimepicker({
			autoclose: true,
			startDate: new Date()
		});

		function validateStartTimeAndEndTime() {
			if ($('input[name="expireBeginDate"]').val() >= $('input[name="expireEndDate"]').val()) {
				$.modal.alertWarning("终止时间必须大于开始时间");
				return false;
			}
			return true;
		}

		function selectExpireStatus(i) {
			if (i == 0) {
				$(".tempExpireDate").hide();
			} else {
				$(".tempExpireDate").show();
			}
		}
	</script>
</body>
</html>
